﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Baza.EF.BLL;
using Baza.EF.DAL;


namespace Pep_3014_3070.Customers
{
    public partial class HistoryReservation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            RezervacijeRepeater1.DataSource = DACustomers.getAllReservations(Convert.ToInt32(HttpContext.Current.User.Identity.Name));
            RezervacijeRepeater1.DataBind();
        }

        protected void RezervacijeRepeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "OcijeniBtn")
            {

                foreach (RepeaterItem item in RezervacijeRepeater1.Items)
                {
                    TextBox ID = (TextBox)item.FindControl("ApartmanIDInput");
                    
                    if (Convert.ToInt32(ID.Text) == Convert.ToInt32(e.CommandArgument))
                    {
                        
                            DropDownList ocjena = (DropDownList)item.FindControl("OcjenaDropDownList");
                            
                            if (Convert.ToInt32(ocjena.SelectedIndex) != 0)
                            {
                                DateTime chkOut = Convert.ToDateTime(((Label)item.FindControl("lblCheckOut")).Text);
                                DACustomers.Ocjeni(Convert.ToInt32(e.CommandArgument), Convert.ToInt32(ocjena.SelectedIndex), Convert.ToInt32(HttpContext.Current.User.Identity.Name));
                                AlertMessage("Uspjesno ste ocijenili Apartman!");
                                return;
                            }
                            else
                                AlertMessage("Potrebno je odabrati ocjenu!");
                    }
                }
            }
        }

        private void AlertMessage(string errorMsg)
        {

            string message = "alert('" + errorMsg + "')";
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "alert", message, true);


        }



    }
}